############################
#          构建阶段         #
############################
FROM node:12.8.1-alpine as build_env
# 定义工作目录
WORKDIR /app
# 拷贝文件到容器
COPY . /app/
# 执行命令
RUN npm set audit false && \
    npm config set registry https://registry.npm.taobao.org && \
    npm install --unsafe-perm && \
    npm run build:stage && \
    npm run test

############################
#          打包阶段        #
############################
FROM nginx:1.16.1-alpine
# 把构建阶段打包好的静态文件拷贝到Nginx容器
COPY --from=build_env /app/dist /usr/share/nginx/html
# 拷贝nginx.conf文件
COPY deploy/nginx.conf /etc/nginx/nginx.conf
RUN echo "ok" > /usr/share/nginx/html/healthz.html